package com.dynamic.mybatis.core.utils;

import java.util.Collection;
import java.util.Random;

public class RandomUtils {

    public static Integer random(int min, int max) {
        Random random = new Random();
        return random.nextInt(max) + min;
    }

    public static <T> T random(T... objects) {
        if (objects == null || objects.length < 1) {
            return null;
        }
        Integer random = random(0, objects.length);
        return objects[random];
    }

    public static <T> T random(Collection<T> collection) {
        if (collection == null || collection.size() < 1) {
            return null;
        }
        Integer random = random(0, collection.size());
        return (T) collection.toArray()[random];
    }
}
